/**
 * @file     maxVowels.js
 * @brief    [1456. 定长子串中元音的最大数目](https://leetcode.cn/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/)
 * @author   Zhu
 * @date     2024-11-21 18:48
 */

/**
 * @param {string} s
 * @param {number} k
 * @return {number}
 */
var maxVowels = function (s, k) {
    const vowels = 'aeiou'.split('');
    const isVowel = (c) => vowels.includes(c);

    const n = s.length;
    const table = Array(n).fill(0);
    let i = 0,
        windowCount = 0,
        max = 0;
    while (i < n) {
        table[i] = isVowel(s[i]);
        windowCount += table[i] - (i < k ? 0 : table[i - k]);
        if (windowCount > max) max = windowCount;
        i++;
    }

    return max;
};
